﻿using Cty.SprayingSCADA.Extensions;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Cty.SprayingSCADA.UserControls
{
    public partial class UserCounterButton : UIUserControl
    {
        private UIStyle Style;
        private Color defaultFillColor;
        private Color defaultRectColor;
        public UserCounterButton()
        {
            InitializeComponent();

            this.Load += UserCounterButton_Load;
        }

        private void UserCounterButton_Load(object? sender, EventArgs e)
        {
            UIExtension.SetStyleManager = SetStyle;// 设置样式管理器
        }
        //设置样式的方法
        private void SetStyle(UIStyleManager manager)
        {
            //设置按钮主题为软件主题
            this.btn_Counter.Style = manager.Style;
            //存储软件主题
            Style = manager.Style;

            //保存当前主题的默认样式
            defaultFillColor = this.btn_Counter.FillColor;
            defaultRectColor = this.btn_Counter.RectColor;
        }

        private string buttonName = "空运行";
        [Browsable(true)]//可以在属性窗口显示
        [Category("自定义属性")]//分类
        [Description("按钮的名称")]
        public string ButtonName
        {
            get { return buttonName; }
            set
            {
                buttonName = value;
                this.btn_Counter.Text = buttonName;
            }
        }

        private int counterButtonSymbol;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("按钮的标签")]

        public int CounterButtonSymbol
        {
            get { return counterButtonSymbol; }
            set
            {
                counterButtonSymbol = value;
                this.btn_Counter.Symbol = counterButtonSymbol;
            }
        }

        private bool countButtonState;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("取反按钮状态")]
        public bool CounterButtonState
        {
            get { return countButtonState; }
            set
            {
                countButtonState = value;
                if (countButtonState)
                {
                    //设置打开(按下)状态的按钮填充与边框颜色
                    this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                    this.btn_Counter.RectColor = this.btn_Counter.RectPressColor;
                }
                else
                {
                    //设置关闭状态下的按钮填充与边框颜色
                    //如果当前按钮主题不等于软件全局主题(切换过)
                    if (this.btn_Counter.Style != Style)
                    {
                        //改变过主题则设置当前主题的颜色
                        this.btn_Counter.Style = Style;
                    }
                    else
                    {
                        //没改变则恢复为原来的颜色
                        this.btn_Counter.FillColor = defaultFillColor;
                        this.btn_Counter.RectColor = defaultRectColor;
                    }

                }
            }
        }
        private string variableName = "";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("获取变量名称")]
        public string VariableName
        {
            get { return variableName; }
            set { variableName = value; }
        }
        //使用事件
        [Browsable(true)]
        [Category("自定义事件")]
        [Description("点击事件")]
        public event EventHandler ClickEvent;
        private void btn_Counter_Click(object sender, EventArgs e)
        {
            //方法的具体逻辑不在控件代码内，外部调用时传入事件对象执行
            ClickEvent?.Invoke(this, e);
        }
    }
}
